home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Database / RandomTableView / TableViewController.m < prev    next >
Text File  |  1994-02-15  |  2KB  |  75 lines

  1. /* TableViewController.m:
  2.  * You may freely copy, distribute, and reuse the code in this example.
  3.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  4.  * fitness for any particular use.
  5.  *
  6.  * 
  7.  *
  8.  */
  9.  
  10.  
  11. #import <dbkit/dbkit.h>
  12.  
  13. #import "TableViewController.h"
  14. #import "RandomDataSource.h"
  15. #define ROWCOUNT    20
  16. #define    COLUMNCOUNT    4
  17.  
  18. @implementation TableViewController
  19.  
  20. - appDidInit:sender
  21. {
  22.     NXRect    viewFrame;
  23.     int    i;
  24.  
  25.     [[tableView getFrame:&viewFrame] free];
  26.     tableView = [[DBTableView alloc] initFrame:&viewFrame];
  27.     [[window contentView] addSubview:tableView];
  28.  
  29.     theDataSource = [[RandomDataSource alloc] init];
  30.     [theDataSource setRows:ROWCOUNT];
  31.     [theDataSource setColumns:COLUMNCOUNT];
  32.     [theDataSource loadData];
  33.     for (i= 0;  i < COLUMNCOUNT;  i++) {
  34.             char buf[100];
  35.             sprintf(buf, "Column %d", i);            
  36.             [tableView addColumn:(id) i withTitle:buf];
  37.         }
  38.  
  39.     [tableView setDataSource:theDataSource];
  40.     [tableView setDelegate:self];
  41.     [self setUpTableView];
  42.      
  43.     return self;
  44. }
  45.  
  46.  
  47. - setUpTableView
  48. {
  49.     int i;
  50.     id <DBTableVectors>    columnVector = nil;
  51.     
  52.     /*
  53.      *  Set up tableview with some default configuration.
  54.      */
  55.     [window disableFlushWindow];
  56.     [tableView setMode:DB_LISTMODE];
  57.      [tableView acceptArrowKeys:YES];
  58.     [tableView allowVectorResizing:YES];
  59.     
  60.     /* initialize the tableview with a fixed column width */
  61.     for (i= 0;  i < COLUMNCOUNT;  i++) {
  62.             columnVector = [tableView columnAt:i];
  63.             [columnVector setMinSize:50.0];        
  64.         }
  65.     
  66.     [tableView setEditable:YES];
  67.     [tableView setColumnHeadingVisible:YES];
  68.     
  69.     [[window reenableFlushWindow] flushWindow];
  70.     [tableView display];
  71.     return self;
  72. }
  73.  
  74. @end
  75.